#include "addstuface.h"
#include "ui_addstuface.h"

addStuface::addStuface(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::addStuface)
{
    ui->setupUi(this);

    appDir = QCoreApplication::applicationDirPath();
}

/* 点击确定按钮 */
void addStuface::on_sureBtn_clicked()
{
    QFile file(appDir + "/stuInfo.txt");
    if (file.exists() == false)
    {
        qDebug() << "创建stuInfo文件" << endl;
    }

    file.open(QIODevice::WriteOnly | QIODevice::Append);

    QTextStream out(&file);
    // 设置编码为 UTF-8
    out.setCodec("UTF-8");

    out << ui->le_name->text();
    out << "+";
    out << ui->le_id->text();
    out << "+";
    out << ui->le_password->text();
    out << "+";
    out << "0";
    out << "\n";

    file.close();

    this->hide();
    ui->le_name->clear();
    ui->le_id->clear();
    ui->le_password->clear();

    emit updataView();
}

/* 点击取消按钮 */
void addStuface::on_cancelBtn_clicked()
{
    this->hide();
    ui->le_name->clear();
    ui->le_id->clear();
    ui->le_password->clear();
}

addStuface::~addStuface()
{
    delete ui;
}
